
#ifndef  __FLASH_IF_H
#define  __FLASH_IF_H

#include "stm32g0xx_hal.h"

#define    FLASH_START_ADDR                    ((uint32_t)0x08000000)
#define    FLASH_TOTAL_SIZE                    (0x10000)
#define    FLASH_END_ADDR                      (FLASH_START_ADDR + FLASH_TOTAL_SIZE)

/* bootloader size 10K */
#define    FLASH_BOOTLOADER_SIZE               (0x2000)

#define    FLASH_APP_REGION_OFFSET             FLASH_BOOTLOADER_SIZE
#define    FLASH_APP_REGION_START_ADDR         (FLASH_START_ADDR + FLASH_APP_REGION_OFFSET)

/* app region is 27K */
#define    FLASH_APP_REGION_SIZE               (0x7000)
#define    FLASH_APP_PAGE_NUM                  ( FLASH_APP_REGION_SIZE / FLASH_PAGE_SIZE)

/* upload region start addr */
#define    FLASH_UPLOAD_REGION_START_ADDR     (FLASH_APP_REGION_START_ADDR + FLASH_APP_REGION_SIZE)
#define    FLASH_UPLOAD_REGION_SIZE           (FLASH_END_ADDR - FLASH_UPLOAD_REGION_START_ADDR)

#define    FLASH_UPLOAD_REGION_PAGE_NUM       (FLASH_UPLOAD_REGION_SIZE / FLASH_PAGE_SIZE)

typedef enum {
	FLASH_WRITE_SUCCESS = 0,
	FLASH_WRITE_ADDR_EXCEED,
	FLASH_WRITE_DATA_VERIFY_FAIL,
	FLASH_WRITE_PROGRAM_FAIL
}FLashWriteStatus;


void FLASH_If_Init(void);
uint32_t FLASH_If_Erase(uint32_t start , uint32_t page_num);
uint32_t FLASH_If_Write(uint32_t flash_addr, uint64_t *p_source, uint32_t length);
#endif
